#!/usr/bin/python
# -*- coding:utf-8 -*-
f=open(r'd:/creator/output_node.txt','w')
f.truncate()
b=3 #输出节点数+1
f.write('module output_node(')
for i in range(1,b):#输出层神经元的输入数据节点申明
	f.write('y'+str(i)+','+'\n')
for i in range(1,b):#输出层单个神经元对应的权重
	f.write('v'+str(i)+','+'\n')#输出层单个神经元的权重
f.write('th_o,o_out,clk,en);')#输出层单个神经元的偏置
f.write('\ninput [7:0]')#输出层神经元输入数据和权重节点
for i in range(1,b):
	f.write('y'+str(i)+',')
for i in range(1,b):
	f.write('v'+str(i)+',')
f.write('th_o;')
f.write('\ninput clk,en;')
f.write('\noutput reg [7:0] o_out;')
f.write('\nalways@(posedge clk) begin')
f.write('\n  if(!en) begin')
f.write('\n    o_out <= relu(')
for i in range(1,b):#输出层单个神经元加权求和
	f.write('y'+str(i)+'*'+'v'+str(i)+'+')
f.write('(-th_o));')#输出层单个神经元的偏置
f.write('\n  end')
f.write('\n  else begin')
f.write('\n    o_out <= o_out;')
f.write('\n  end')
f.write('\nend')
f.write('\n\nfunction [7:0] relu(input [7:0] a);\nbegin\n  if(a<0) begin\n    relu = 0;\n  end\n  else begin\n    relu = a;\n  end\nend\nendfunction')
f.write('\nendmodule')
f.close()